import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '@/views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:'/home'
  },{
    path: '/home',
    name: 'home',
    component: HomeView,
    children:[
      {
        path: '/userDetail',
        name: 'userDetail',
        component: ()=> import ('@/views/userDetail.vue')
      },
      {
        path: '/test',
        name: 'test',
        component: ()=> import ('@/views/test.vue')
      },{
        path: '/history',
        name: 'history',
        component: ()=> import ('@/views/history.vue')
      },{
        path: '/card',
        name: 'card',
        component: ()=> import ('@/views/card.vue')
      },{
        path: '/paperManage',
        name: 'paperManage',
        component: ()=> import ('@/views/paperManage.vue')
      },{
        path: '/scoreManage',
        name: 'scoreManage',
        component: ()=> import ('@/views/scoreManage.vue')
      },
    ]
  },{
    path: '/login',
    name: 'login',
    component: ()=> import ('@/views/login.vue')
  },{
    path: '/fakeTest',
    name: 'fakeTest',
    component: ()=> import ('@/views/fakeTest.vue')
  },{
    path: '/recite',
    name: 'recite',
    component: ()=> import ('@/views/recite.vue')
  },{
    path: '/analyze',
    name: 'analyze',
    component: ()=> import ('@/views/analyze.vue')
  },
]
const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  // if (to.meta.title) {
  //   document.title = to.meta.title;
  // }
  if(localStorage.getItem('islogin')!=1 && to.path!='/login'){
    next({
      name: 'login', // 跳转到登录页
    })
  }else{
    next()
  }
});

export default router
